package com.eureka.client.demo.lancher;

import java.util.ArrayList;
import java.util.List;

/**
 * 责任链模式,将根据addHandler顺序依次调用ServiceLancherHandler的handle方法
 */
public class ServiceLancherHandlerChain {
    public List<ServiceLancherHandler> handlers = new ArrayList<>();

    public void addHandler(ServiceLancherHandler handler){
        this.handlers.add(handler);
    }

    public void handle(String serviceId){
        for (ServiceLancherHandler handler : this.handlers) {
            boolean isSuccess = handler.handle(serviceId);
            if (isSuccess){
                break;
            }
        }
    }
}
